<template>
	<!-- 截止2022年依然无效，至少效果不好，还是一点一点的加载，目前有一个折中的方式，初始把图片的css属性opacity设置为0，然后在load事件完成以后改成1，加一个动画效果，就能比较好的实现懒加载效果了 -->
	<view class="waterfall-item" @tap="onTap" :data-currentId="params.id" :data-jumpId="params.order_status">
		<view class="p_relative">
			<view class="p_absolute f10 radius5 p6 cffffff" style="top: 5px; left: 5px; background-color: rgba(0, 0, 0, 0.6)" v-if="params.order_status == 1">
				<text>置顶</text>
			</view>
			<view class="dflex p_absolute f10 radius5 p6 cffffff" style="bottom: 5px; left: 5px; background-color: rgba(0, 0, 0, 0.5)" v-if="params.order_status != 2">
				<u-icon name="eye" color="#fff"></u-icon>
				<text class="ml5">{{ params.view_count }}</text>
			</view>
			<image 
				:src="params.cover" 
				mode="widthFix" 
				class="lazyload" 
				@load="emitHeight" 
				@error="emitHeight" 
				:animation="animationData"
			>
			</image>
		</view>
		<!-- <u-image :src="params.cover" mode="widthFix" @load="emitHeight" @error="emitHeight"></u-image> -->
		<view class="content">
			<view class="u-line-2 fbold">{{ params.title == "" ? params.auto_title : params.title}}</view>
			<view class="dflex jcsb mt12">
				<view class="dflex user_list_avatar_and_name aic">
					<image :src="params.user.avatar" :lazy-load="true" mode="scaleToFill"></image>
					<text class="f12">{{params.user.name}}</text>
				</view>
				<view class="dflex aic  user_list_avatar_and_name">
					<image src="/static/zan.png" mode="heightFix"></image>
					<text class="f12">{{params.like_count}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"helang-waterfall",
		props:{
			params:{
				type: Object,
				default(){
					return {}
				}
			},
			tag:{
				type:String | Number,
				default:''
			},
			index:{
				type:Number,
				default:-1
			}
		},
		data() {
			return {
				animationData : {}
			};
		},
		methods:{
			// 发出组件高度信息，在此处可以区分正确和错误的加载，给予错误的提示图片
			emitHeight(e){
				const query = uni.createSelectorQuery().in(this);
				query.select('.waterfall-item').boundingClientRect(data => {
					let height = Math.floor(data.height);
					this.$emit("height",height,this.$props.tag);
					this.lazyImg()
				}).exec();
			},
			onTap(e){
				// this.$emit("click",this.$props.index,this.$props.tag,e);
				this.$emit("click",this.$props.index,this.$props.tag,e);
			},
			lazyImg() {			
				//创建动画
				var animation = uni.createAnimation({
					transformOrigin: "ease-in",
					duration: 100, //动画持续1秒
					// timingFunction: 'linear',  //linear 全程匀速运动
					// delay:300  //延迟两秒执行动画
				}) 
				this.animation = animation

				animation.opacity(1).step()
				
				this.animationData = animation.export()
			},
		}
	}
</script>

<style lang="scss" scoped>
.waterfall-item{
	background-color: #fff;
	border-radius: 4px;
	font-size: 28rpx;
	color: #666;
	margin-bottom: 25rpx;
	padding: 0 0 30rpx 0;
	
	image{
		display: block;
		width: 100%;
		// 默认设置一个图片的大约值
		height: 350rpx;
		border-radius: 10px;
	}
	
	.content{
		margin-top: 16rpx;
		
		.money{
			color: #fa3534;
			margin-top: 8rpx;
		}
		
		.label{
			background-color: #fa3534;
			color: #fff;
			font-size: 20rpx;
			padding: 4rpx 16rpx;
			border-radius: 20rpx;
		}
		
		.shop-name{
			font-size: 20rpx;
			color: #999;
		}
	}
		
	.user_list_avatar_and_name image {
		width: 15px;
		height: 15px;
		border-radius: 15px;
		margin-right: 2px;
	}
	
	.lazyload {
		opacity: 0;
	}
	
}
</style>
